package com.sosee.cgfw.fragment;

import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.lidroid.xutils.BitmapUtils;
import com.lidroid.xutils.HttpUtils;
import com.sosee.cgfw.R;
import com.sosee.cgfw.utils.Constans;
import com.sosee.cgfw.utils.Utils;

import java.net.MalformedURLException;
import java.net.URL;

/**
 * Created by Thinkpad on 2016/4/22.
 * //启动时 加载的广告滑动页
 */
public class SplashAdFragment extends Fragment {
    private View view;
    private HttpUtils httpUtils;
    private String imgUrl;//加载滑动图片网址
    private BitmapUtils bitmapUtils;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view=inflater.inflate(R.layout.fragment_splash_ad,null);
        initData();
        return view;
    }

    public void initData(){
        httpUtils=new HttpUtils();
        imgUrl=getArguments().getString("url", "");
    }

    @Override
    public void onStart() {
        super.onStart();
//        bitmapUtils.display(view, imgUrl);
        URL url= null;
        try {
            url = new URL(imgUrl);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        Utils.onLoadImage(url, new Utils.OnLoadImageListener() {
            @Override
            public void OnLoadImage(Bitmap bitmap, String bitmapPath) {
                view.setBackgroundDrawable(new BitmapDrawable(bitmap));
            }
        });
    }
}
